﻿using System.Collections.Generic;
using System.Threading;
namespace MessageHandlingServer.Server1
{
    class MyBlockedQueue<T> : IQueue<T>
    {
        private readonly Queue<T> queue = new Queue<T>();

        public void Enqueue(T item)
        {
            lock (queue)
            {
                queue.Enqueue(item);
                 // wake up any blocked dequeue
                 Monitor.PulseAll(queue);
            }
        }
        public T Dequeue()
        {
            lock (queue)
            {
                while (queue.Count == 0)
                {
                    Monitor.Wait(queue);
                }
                T item = queue.Dequeue();
                return item;
            }
        }
    }
}